@include('admin.layout.bone_header')


<div class="layui-btn-container">
</div>

<table class="layui-hide" id="think-table" lay-filter="think-table"></table>


<script id="barDemo" type="text/html">
    @{{#  if(d.spread_id ==0 && d.user_id !=1){ }}
         <a class="layui-btn layui-btn-xs" lay-event="update_spread">修改推荐人</a>
    @{{#  } }}
    <a class="layui-btn layui-btn-xs" lay-event="update_vip_level_index">修改等级</a>


</script>

<script>

    layui.use('table', function () {
        let table = layui.table;
        UI.getPageTable(table, "{{route('admin.users.user')}}?type=1", [
            {field: 'user_id', title: 'ID', width:80, sort: true,fixed: 'left'}
            ,{field: 'nickname',title:'用户昵称'}
            ,{field: 'user_phone',title:'手机号'}
            ,{field: 'k_price',title:'余额'}
            ,{field: 'd_price',title:'扶持基金'}
            ,{field: 'spread_id',title:'推荐人'}
            ,{field: 'vip_index',title:'用户身份',templet:function (d){
                let arr = ['游客','普通代理','高级代理','普通老板','高级老板','平台股东'];

                return  arr[d['vip_level_index']]

            }}
            ,{field: 'created_at',title:'注册时间',templet:function (d){
                console.log(d['created_at']);
                return layui.util.toDateString(parseInt(d['created_at'])*1000,'yyyy-MM-dd HH:mm:ss')
           }}
            ,{fixed: 'right',title:'操作', align:'center',width:200, toolbar: '#barDemo'}
        ]);

        table.on('tool(think-table)', function (obj) {
            let data = obj.data;
            if(obj.event == 'update_spread'){
                    UI.openLayer("{{route('admin.user.update_spread')}}?user_id="+data['user_id']);
            }else if(obj.event == 'change_yong'){

                UI.openLayer("{{route('admin.users.change_yong')}}?user_id="+data['user_id']);
            }else if(obj.event == 'update_vip_level_index'){

                UI.openLayer("{{route('admin.users.update_vip_level_index')}}?user_id="+data['user_id']);
            }
        });
        let $ = layui.$, active = {

            reload:function (){
                let search_key = $('#search_key');
                //执行重载
                table.reload('think-table', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        'search_key':search_key.val(),
                    }
                });
            }
        };
        $('.layui-btn-container .layui-btn').on('click', function () {
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $('.search .layui-btn').on('click', function () {
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    })


</script>


@include('admin.layout.bone_footer')
